<template>
  <div id="gztDiv" style="overflow: auto">
    <TaskFormView
      ref="formView"
      @fGetEnclosure="sGetEnclosure"
      @f_SetFormData="s_SetFormData"
      @f_getStepBtnList="s_getStepBtnList"
      :pattern="Number($route.params.pattern)"
      :applyid="$route.params.applyid"
    ></TaskFormView>
  </div>

</template>
<script>
import { getHandleParams } from '@/api/workflow/wf_ProcessInstance.js'
import { getUrlParameter } from '@/utils/util.js'
export default {
    data () {
        return {
            processState: null, // 流程状态
            loading: true // 页面参数是否初始化完成
        }
    },
    async created () {
        // 接收赣政通传过来的参数
        const url = window.location.search
        const taskid = getUrlParameter(url, 'taskid')
        this.$route.params.taskid = taskid
        const stepid = getUrlParameter(url, 'stepid')
        this.$route.params.pattern = '4'
        const n_stepid = getUrlParameter(url, 'n_stepid')
        this.$route.params.stepid = stepid != '' ? stepid : n_stepid
        const modelKey = getUrlParameter(url, 'modelKey')
        this.$route.params.modelKey = modelKey

        const userid = getUrlParameter(url, 'userid')
        this.$route.params.userid = userid

        // 防止归档页面掉参 缓存
        if (this.$route.query) {
            for (const key in this.$route.query) {
                if (key != 'stepid') {
                    this.$route.params[key] = this.$route.query[key]
                }
            }
        }
        // 根据taskid查询页面参数
        // await getHandleParams(this.$route.params.taskid)
        //     .then((res) => {
        //         // console.log('页面所需参数', res)
        //         if (res.code == 0 && res.data != null) {
        //             for (const key in res.data) {
        //                 if(key == 'stepid'){
        //                     this.$route.query[key] = res.data[key]
        //                 }
        //                 this.$route.params[key] = res.data[key]
        //             }
        //             this.processState = res.data.state
        //         } else {
        //             this.$message.error('查询处理页面所需要的参数失败!')
        //         }
        //     })
        //     .finally(() => {
        //         this.loading = false
        //     })
        // console.log('路由参数',this.$route)
    },
    mounted () {
        // 设置父级元素app可浮动
        const childElement = document.getElementById('gztDiv')
        if (childElement) {
            const parentElement = childElement.parentNode
            if (parentElement && parentElement.id == 'app') {
                parentElement.style.overflow = 'auto'
            }
        }
    },

    methods: {
        // 找到按钮回显环节需要用到的id
        s_getStepBtnList (stepid) {
            console.log('管理员按钮', this.$route.params.pattern)
            this.$nextTick(() => {
                if (this.$refs.btnRef) {
                    this.$refs.btnRef.getStepBtnList(stepid)
                }
            })
        },
        // 父表单组件调用, 给表单填写数据
        s_SetFormData (body) {
            this.$refs.btnRef.sSetFormData(body)
        },
        // 子组件找到的文件类型给值方法
        sGetEnclosure (list) {
            this.enclosureList = []
            list &&
                list.forEach((v) => {
                    const item = {}
                    this.initItme(item, v)
                    this.enclosureList.push(item)
            })
        console.log('表单控件类型', this.enclosureList)
        }
    },
    components: {
        TaskFormView: () => import('@/views/workflow/Wf_TaskForm.vue')
    }
}
</script>
<style lang="scss" scoped>
    #app {
        overflow: auto !important;
    }
    ::v-deep .theme_default_task .tableBox{
        margin: 0;
        padding-top: 0;
        width: 100%;
        // height: 50%;
    }
    // ::v-deep .formItemBox label span{
    //     font-size: 12px;
    // }
    ::v-deep .ant-form-item-control{
        line-height: 20px;
    }
    ::v-deep .ant-col-18{
        width: 40%;
    }
    ::v-deep .ant-col-6{
        width: 60%;
    }
</style>
